package cate.game.play.skill.passive.common;

import cate.common.util.XT;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.result.SkillAnounceResult;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 阵亡时能立即复活的被动技能
 */
public abstract class 立即复活PH extends PassiveHandler {

	//复活次数
	protected int resurrectNum;


	@Override
	public void immediateRebirth(ActionCtx action) {
		if (skill.owner.isAlive()) {
			return;
		}
		if (!allowResurrect(action)) {
			return;
		}
		if (getResurrectMax() > 0 && resurrectNum >= getResurrectMax()) {
			return;
		}
		if (getChance() > 0 && !XT.chance(getChance())) {
			return;
		}
		boolean success = this.skill.owner.attr.tryResurrect(action, healValue(), ignNoRebirth());
		if (success) {
			resurrectNum++;
			onSuccess(action);
			action.addResult(new SkillAnounceResult().skillSet(this.skill));
		}
	}

	//恢复值
	protected abstract double healValue();

	//最大复活次数
	protected int getResurrectMax(){
		return -1;
	}

	//无视禁活
	protected boolean ignNoRebirth(){
		return false;
	}

	//复活概率
	protected int getChance(){
		return -1;
	}

	//技能自定义的复活规则
	protected boolean allowResurrect(ActionCtx action) {
		return true;
	}

	//技能自定义的成功结算后要处理的事情
	protected void onSuccess(ActionCtx action) {}

}
